<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>学生信息查询</title>
    <link rel="stylesheet" href="{{ url_for('static',filename='css/weui.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/example.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/jquery-weui.css') }}">
    <script src="../static/js/zepto.min.js"></script>
    <script src="../static/js/example.js"></script>
    <script src="../static/js/weui.min.js"></script>
    <script type="text/javascript" src="../static/js/jquery-weui.js"></script>
</head>

<body ontouchstart>
<!-- js中创建div界面，也就是主界面，注意js的id -->
     {# opacity: 1透明度设置 #}
    <div class="page" style="opacity: 1">
        <div class="weui-cells weui-cells_form" id="get-info" style="margin-top: 30px">

  <div class="weui-cell">
        <div class="weui-cell__hd"><label class="weui-label" style="width: 40px">查询</label></div>
    <div class="weui-cell__bd">
      <input class="weui-input" id="input_text" type="text" style="margin-left: 20px" maxlength="20" placeholder="姓名或学号">
    </div>
  </div>

</div>
     <div class="weui-btn-area" style="background-color: #DEB887;">
      <a class="weui-btn confirm" href="javascript:" id="showTooltips">确定</a>
     </div>
        <p style="margin-left: 15px;margin-right: 10px; font-size: 13px; color: #9b9b9b; text-align: left">注：{{ user }}老师请保护学生隐私，查询日志会被记录</p>
     <div class="weui-footer weui-footer_fixed-bottom">
  <p class="weui-footer__text">Copyright © 党委学生工作部、学生处版权所有</p>
    </div>

    <div class="weui-cells__title"></div>
        <div class="weui-cells" id="result_list"></div>
    </div>

</body>
</html>
<script>
    $(function () {
        var sno_rel = /^20[0-9]{8}$/;
        var name_rel =   /^([\u4e00-\u9fa5\·]{2,10})$/;
        var tmpl_none = ' <div style="text-align: center; margin-top:40px;">\n' +
            '                <p style="color:#9B9B9B; font-size:16px ">未找到任何结果</p>\n' +
            '            </div>';
        var tmpl_info = ' <a class="weui-cell weui-cell_access" href="http://jza.gangxi.xiaosikeji.com/mainpage?uid=#uid#">\n' +
            '            <div class="weui-cell__bd">\n' +
            '              <span>#name#</span>\n' +'&nbsp;'+
            '              <span style="margin-left:5px; color:#9B9B9B">#sno#</span>\n' + '&nbsp;&nbsp;'+
            '              <span style="margin-left:5px; color:#9B9B9B">#class_#</span>\n' +
            '            </div>\n' +
            '            <div class="weui-cell__ft"></div>\n' +
            '          </a>';

        $('.confirm').on("click", function () {
            var text = $('#input_text').val().trim();
            if(text.length === 0){
                $.toast('查找内容为空', "forbidden");
            }

              else if(! (name_rel.test(text)|| sno_rel.test(text)) ){
                $.toast('请输入有效姓名或者学号', "forbidden");
            }

            else {
                  var formData = new FormData();
                  formData.append('text', text);
                     $.ajax({
                        type:"POST",
                        url: '{{ url_for('main.search_result') }}',
                        data:formData,
                        dataType:'json',
                        contentType: false,
                        processData: false,
                        cache:false,
                        success: function(data) {
                            if(data['count'] === 0) {
                                    $('.weui-cells__title').html("");
                                    $('.weui-cells__title').append(tmpl_none);
                            }
                            else{
                                 $('.weui-cells__title').html("共找到" + data['count'] + "条结果:");
                                 $('#result_list').html("");
                                 for(var i=0; i<data['info'].length; i++){
                                     if (data['info'][i]['class_'] == null)
                                     { data['info'][i]['class_'] = ''}
                                      if (data['info'][i]['sno'].length > 8) {
                                          var tmpl_info_new = tmpl_info.replace("#name#", data['info'][i]['name']).replace("#sno#", data['info'][i]['sno'])
                                              .replace("#uid#", data['info'][i]['sno']).replace("#class_#", data['info'][i]['class_']);
                                          $('#result_list').append(tmpl_info_new);
                                      }

                                 }

                            }
                        },
                        error: function() {
                            $.toast('服务器繁忙，请稍后重试', "forbidden");
                        }
                 });
            }

        })
    });

</script>